package ui;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JFrame;
import javax.swing.JPanel;

import control.Constants;
import control.Control_UI;


public class KaoFrame extends JFrame{
	
	/**
	 * Default serial UID
	 */
	private static final long serialVersionUID = 1L;
	private Control_UI cltr_ui ;
	private UIMenu menu;
	private UITool tools;
	private UIFamilyTree family_tree;
	private UIOption option ;
	
	private JPanel main_panel;
	
	
	/**
	 * Constructor of frame
	 * @param title
	 * @param con_ui
	 */
	public KaoFrame( Control_UI con_ui) {
		this.cltr_ui = con_ui;
		setPreferredSize(Constants.DIMENTSION_MAIN_WINDOW);
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setTitle(Constants.TITLE_WINDOW_DEFAULT);
		pack();
		
		this.menu = new UIMenu(cltr_ui);
		setJMenuBar(this.menu);
		
		
		// Le Layout
		//GridBagLayout g = new GridBagLayout();
		//window.setLayout(g);
		
		this.tools = new UITool(this.cltr_ui);
		//this.window.add(this.tools, BorderLayout.NORTH);
		
		main_panel = new JPanel();
		main_panel.setLayout(new GridBagLayout());
		build_main_panel();
		
		add(main_panel);
	} 
	

	private void build_main_panel() {
   		GridBagConstraints c = new GridBagConstraints();
   		
   		this.option = new UIOption(this.cltr_ui);
   		
   		c.fill = GridBagConstraints.HORIZONTAL;
   		c.gridx = 0;
   		c.gridy = 0;
   		c.weightx = 1;
   		c.gridwidth = 3;
   		c.gridheight = 2;
		family_tree = new UIFamilyTree(cltr_ui.getYawmSaub(), option);
		main_panel.add(family_tree, c);
		
   		c.gridx = 3;
   		c.gridy = 0;
   		c.weightx = 1;
   		c.gridwidth = 1;
   		c.gridheight = 1;
   		//main_panel.add( this.option, c);
   		
		c.gridx = 3;
   		c.gridy = 1;
   		c.weightx = 1;
   		c.gridwidth = 1;
   		c.gridheight = 1;
		//main_panel.add(new UILog(this.cltr_ui), c );
		
	}


	/**
	 * Refresh the family tree panel  
	 */
	public void refresh_family_tree() {
		this.family_tree.initRoot();
		this.family_tree.refresh_tree();
	}
	
	/**
	 * Show the main window
	 */
	public void showKaoFrame(){
		setVisible(true);
	}
	
	/**
	 * Hide the main window
	 */
	public void hideKaoFrame(){
		setVisible(false);
	}
	
	public JFrame getWindow() {
		return this;
	}


	public UIFamilyTree getFamily_tree() {
		return family_tree;
	}

	

}
